const webpack = require('webpack');
const merge = require('webpack-merge');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');

const webpackBaseConfig = require('./webpack.config.base');

const webpackDevConfig = merge(webpackBaseConfig, {
    devtool: '#cheap-module-source-map',
    mode: 'development',
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify('development'),
            }
        }),
        // 全局开启代码热更替
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new FriendlyErrorsPlugin(),
    ]
})

Object.keys(webpackDevConfig.entry).forEach(function (name) {
    webpackDevConfig.entry[name] = ['webpack-hot-middleware/client?path=/__webpack_hmr&timeout=2000&reload=true'].concat(webpackDevConfig.entry[name])
})

module.exports = webpackDevConfig;